package wbbs.web;

import cn.webwheel.Action;
import cn.webwheel.results.TemplateResult;
import com.google.inject.Inject;
import wbbs.domain.Board;
import wbbs.domain.BoardCategory;
import wbbs.service.BoardService;

import java.sql.SQLException;
import java.util.List;

public class index extends BaseAction {

    @Inject
    BoardService boardService;

    List<BoardCategory> categories;

    @Action
    public Object html() throws SQLException {
        categories = boardService.listCategories();
        for (BoardCategory category : categories) {
            for (Board board : category.boards) {
                board.masters.clear();
                for (String uid : board.masterIds) {
                    board.masters.add(userService.findUser(uid));
                }
            }
        }
        return new TemplateResult(this);
    }

    public List<BoardCategory> getCategories() throws SQLException {
        return boardService.listCategories();
    }
}
